<template>
	<view>
		<cf-car :list="data" @addOrder="addOrder" @clearCar="clearCar" @delCar="delCar" @toDetail="goodsDetail"
			@toOther="toIndex" ref="car">
		</cf-car>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
			}
		},
		onLoad() {},
		onShow() {
			this.getCars()
		},
		methods: {
			//提交订单结算
			addOrder(order) {
				uni.setStorageSync("carGoods", order) //缓存传参
				uni.navigateTo({
					url: "/pagesOne/prePay/prePay"
				})
			},
			//跳转首页
			toIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			//获取购物车商品
			getCars() {
				this.apis.getCar().then(res => {
					console.log(res)
					this.data = res.reverse()
					console.log("cats:"+this.data)
				})
				
			},
			//详情
			goodsDetail(goodsId) {
				uni.navigateTo({
					url: "/pagesOne/goodsDetail/goodsDetail?id=" + goodsId
				})
			},

			//删除功能
			delCar(goodsId) {
				this.apis.delCar({
					goodsId: goodsId
				})
			},
			//清空
			clearCar() {
				let that = this
				that.apis.clearCar().then(res => {
					that.$refs.car.clearCarLocal()
				})
			}

		}
	}
</script>

<style lang="scss">

</style>
